package com.mall.seckill.controller;

import com.github.pagehelper.PageInfo;
import com.mall.common.response.CommonResponse;
import com.mall.entity.TbGoods;
import com.mall.entity.TbSeckill;
import com.mall.seckill.service.SeckillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author White
 * @version 1.0
 * @email 616769721@qq.com
 * @date 2021/7/17 19:45
 */
@RestController
@RequestMapping("/seckill")
@CrossOrigin
public class SeckillController {

    @Autowired
    private SeckillService seckillService;


    /**
     * 添加秒杀配置
     *
     * @param tbSeckill
     * @return {@link Boolean}
     */
    @PostMapping("/addSeckill")
    public CommonResponse addSeckill(@RequestBody TbSeckill tbSeckill){
        return seckillService.addSeckill(tbSeckill);
    }
    @PostMapping("/findAll")
    public PageInfo<TbSeckill> findList(@RequestBody TbSeckill tbSeckill,
                                        @RequestParam(value = "page")Integer page,
                                        @RequestParam(value = "size")Integer size){
        return seckillService.findList(tbSeckill,page,size);
    }

    @PostMapping("/updateSeckill")
    public CommonResponse updateSeckill(@RequestBody TbSeckill tbSeckill){
        return seckillService.updateSeckill(tbSeckill);
    }


    @GetMapping("/deleteById")
    public CommonResponse deleteById(Long id){
        return seckillService.deleteById(id);
    }

    /**
     * 回显
     * @param id
     * @return
     */
    @GetMapping("/hui")
    public TbSeckill hui(Long id){
        return seckillService.hui(id);
    }

    @PutMapping("/updateStatus")
    public CommonResponse updateStatus(Long id,String status){
        return seckillService.updateStatus(id,status);
    }

}
